package com.chinaedu.oc.utils;
import java.util.Objects;

import com.alibaba.fastjson.JSONObject;

/**
 * 返回结果工具类
 *
 */
public class ProcessResult {
		private boolean status;//状态
		private String msg;//错误时 返回msg
		private Object data;//数据
		private int recordsFiltered;//记录总条数
		
		
		public ProcessResult() {
			super();
		}

		public ProcessResult(boolean status, Object data) {
			super();
			this.status = status;
			this.data = data;
		}

		public ProcessResult(boolean status, String msg) {
			super();
			this.status = status;
			this.msg = msg;
		}

		public ProcessResult(boolean status, String msg, Object data) {
			super();
			this.status = status;
			this.msg = msg;
			this.data = data;
		}
		
		public ProcessResult(boolean status, Object data, int recordsFiltered) {
			super();
			this.status = status;
			this.data = data;
			this.recordsFiltered = recordsFiltered;
		}

		public String toJson() {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("status", status);
			if (Objects.nonNull(msg)) {
				jsonObject.put("msg", msg);
			}
			if (Objects.nonNull(data)) {
				jsonObject.put("data", data);
			}
			return jsonObject.toJSONString();
		}
		
		public String toPageJson() {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("status", status);
			if (Objects.nonNull(msg)) {
				jsonObject.put("msg", msg);
			}
			if (Objects.nonNull(data)) {
				jsonObject.put("data", data);
			}
			if(Objects.nonNull(recordsFiltered)){
				jsonObject.put("recordsFiltered", recordsFiltered);
			}
			return jsonObject.toJSONString();
		}

		public boolean isStatus() {
			return status;
		}

		public void setStatus(boolean status) {
			this.status = status;
		}

		public String getMsg() {
			return msg;
		}

		public void setMsg(String msg) {
			this.msg = msg;
		}

		public Object getData() {
			return data;
		}

		public void setData(Object data) {
			this.data = data;
		}

		public int getRecordsFiltered() {
			return recordsFiltered;
		}

		public void setRecordsFiltered(int recordsFiltered) {
			this.recordsFiltered = recordsFiltered;
		}
		
		
	}